/**
 * Project Name:mauto-web
 * File Name:ApiAutoDoctorController.java
 * Package Name:com.inftech.mauto.sys.web.front
 * Date:2016年10月17日下午10:02:10
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.sys.web.front;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inftech.mauto.common.base.BaseController;
import com.inftech.mauto.common.base.BusinessException;
import com.inftech.mauto.common.constant.HttpStatusCodeEnum;
import com.inftech.mauto.sys.service.CarDoctorService;
import com.inftech.mauto.sys.service.CustomerServiceService;

/**
 * ClassName:ApiCustomerServiceController <br/>
 * Function: 客服接口. <br/>
 * Date: 2016年10月17日 下午10:02:10 <br/>
 * 
 * @author puyf
 * @version
 * @since JDK 1.7
 */
@Controller
@RequestMapping("/api/customerService")
public class ApiCustomerServiceController extends BaseController {

	/**
	 * 注入客服业务层
	 */
	@Autowired
	protected CustomerServiceService customerServiceService;

	/**
	 * 
	 * list:获取客服列表. <br/>
	 *
	 * @author puyf
	 * @param request
	 * @since JDK 1.7
	 */
	@RequestMapping(value = "/list", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String list(HttpServletRequest request) throws Exception {
		String outJson = "";
		try {
			// 获取客服列表
			List<Map<String, Object>> carDoctorList = customerServiceService.queryCustomerServiceListFront();
			LOG.info("获取客服列表成功");
			// 返回结果
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.STATUS_CODE_200;
			outJson = getOutJson(statusCode, true, statusCode.toString(), carDoctorList);
		} catch (Exception e) {
			if (e instanceof BusinessException) {
				throw e;
			}
			LOG.error("获取客服列表失败", e);
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.SCOPE_BASE;
			outJson = getOutJson(statusCode, false, statusCode.toString(), null);
		}
		return outJson;
	}

	/**
	 * 
	 * detail:获取客服详情. <br/>
	 *
	 * @author puyf
	 * @param request
	 * @since JDK 1.7
	 */
	@RequestMapping(value = "/detail/{id}", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String detail(@PathVariable int id, HttpServletRequest request) throws Exception {
		String outJson = "";
		try {
			// 获取客服详情
			Map<String, Object> carDoctorMap = customerServiceService.queryCustomerService(id);
			LOG.info("获取客服详情成功");
			// 返回结果
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.STATUS_CODE_200;
			outJson = getOutJson(statusCode, true, statusCode.toString(), carDoctorMap);
		} catch (Exception e) {
			if (e instanceof BusinessException) {
				throw e;
			}
			LOG.error("获取客服详情失败", e);
			HttpStatusCodeEnum statusCode = HttpStatusCodeEnum.SCOPE_BASE;
			outJson = getOutJson(statusCode, false, statusCode.toString(), null);
		}
		return outJson;
	}
}
